from pydantic import BaseModel, Field
from typing import Optional, List, Dict
from datetime import datetime


class FacebookVideoFormatInfo(BaseModel):
    """Facebook视频格式信息DTO"""
    format_id: str = Field(..., description="格式ID")
    ext: str = Field(..., description="文件扩展名")
    resolution: str = Field(..., description="分辨率")
    filesize: Optional[int] = Field(None, description="文件大小(字节)")
    filesize_approx: Optional[int] = Field(None, description="文件大小(大约)")
    url: Optional[str] = Field(None, description="下载链接")
    quality: Optional[float] = Field(None, description="质量分数")
    format_note: Optional[str] = Field(None, description="格式说明")
    fps: Optional[float] = Field(None, description="帧率")
    vcodec: Optional[str] = Field(None, description="视频编码")
    acodec: Optional[str] = Field(None, description="音频编码")


class FacebookVideoInfo(BaseModel):
    """Facebook视频信息DTO"""
    video_id: str = Field(..., description="视频ID")
    title: str = Field(..., description="视频标题")
    uploader: Optional[str] = Field(None, description="上传者")
    uploader_id: Optional[str] = Field(None, description="上传者ID")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    view_count: Optional[int] = Field(None, description="观看次数")
    upload_date: Optional[str] = Field(None, description="上传日期")
    description: Optional[str] = Field(None, description="视频描述")
    thumbnail: Optional[str] = Field(None, description="缩略图链接")
    webpage_url: Optional[str] = Field(None, description="网页链接")
    formats: List[FacebookVideoFormatInfo] = Field(default_factory=list, description="可用格式列表")


class FacebookInfoResponse(BaseModel):
    """获取Facebook视频信息响应DTO"""
    video_id: str = Field(..., description="视频ID")
    title: str = Field(..., description="视频标题")
    uploader: Optional[str] = Field(None, description="上传者")
    uploader_id: Optional[str] = Field(None, description="上传者ID")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    view_count: Optional[int] = Field(None, description="观看次数")
    upload_date: Optional[str] = Field(None, description="上传日期")
    description: Optional[str] = Field(None, description="视频描述")
    thumbnail: Optional[str] = Field(None, description="缩略图链接")
    webpage_url: Optional[str] = Field(None, description="网页链接")
    formats: List[FacebookVideoFormatInfo] = Field(default_factory=list, description="可用格式列表")


class FacebookDownloadUrlInfo(BaseModel):
    """Facebook下载链接信息DTO"""
    video_id: str = Field(..., description="视频ID")
    title: str = Field(..., description="视频标题")
    uploader: Optional[str] = Field(None, description="上传者")
    download_url: str = Field(..., description="下载链接")
    format: str = Field(..., description="视频格式")
    resolution: str = Field(..., description="分辨率")
    filesize: Optional[int] = Field(None, description="文件大小(字节)")
    filesize_approx: Optional[int] = Field(None, description="文件大小(大约)")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    thumbnail: Optional[str] = Field(None, description="缩略图链接")
    fps: Optional[float] = Field(None, description="帧率")
    vcodec: Optional[str] = Field(None, description="视频编码")
    acodec: Optional[str] = Field(None, description="音频编码")
    webpage_url: Optional[str] = Field(None, description="网页链接")


class FacebookDownloadUrlResponse(BaseModel):
    """获取Facebook下载链接响应DTO"""
    video_id: str = Field(..., description="视频ID")
    title: str = Field(..., description="视频标题")
    uploader: Optional[str] = Field(None, description="上传者")
    download_url: str = Field(..., description="下载链接")
    format: str = Field(..., description="视频格式")
    resolution: str = Field(..., description="分辨率")
    filesize: Optional[int] = Field(None, description="文件大小(字节)")
    filesize_approx: Optional[int] = Field(None, description="文件大小(大约)")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    thumbnail: Optional[str] = Field(None, description="缩略图链接")
    fps: Optional[float] = Field(None, description="帧率")
    vcodec: Optional[str] = Field(None, description="视频编码")
    acodec: Optional[str] = Field(None, description="音频编码")
    webpage_url: Optional[str] = Field(None, description="网页链接")


class FacebookQualityUrlInfo(BaseModel):
    """Facebook质量下载链接信息DTO"""
    url: str = Field(..., description="下载链接")
    format: str = Field(..., description="文件格式")
    filesize: Optional[int] = Field(None, description="文件大小(字节)")
    filesize_approx: Optional[int] = Field(None, description="文件大小(大约)")
    fps: Optional[float] = Field(None, description="帧率")
    vcodec: Optional[str] = Field(None, description="视频编码")
    acodec: Optional[str] = Field(None, description="音频编码")


class FacebookMultiQualityInfo(BaseModel):
    """Facebook多质量下载信息DTO"""
    video_id: str = Field(..., description="视频ID")
    title: str = Field(..., description="视频标题")
    uploader: Optional[str] = Field(None, description="上传者")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    thumbnail: Optional[str] = Field(None, description="缩略图链接")
    quality_urls: Dict[str, FacebookQualityUrlInfo] = Field(..., description="不同质量的下载链接")
    available_qualities: List[str] = Field(..., description="可用的质量选项")


class FacebookMultiQualityResponse(BaseModel):
    """获取Facebook多质量下载链接响应DTO"""
    video_id: str = Field(..., description="视频ID")
    title: str = Field(..., description="视频标题")
    uploader: Optional[str] = Field(None, description="上传者")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    thumbnail: Optional[str] = Field(None, description="缩略图链接")
    quality_urls: Dict[str, FacebookQualityUrlInfo] = Field(..., description="不同质量的下载链接")
    available_qualities: List[str] = Field(..., description="可用的质量选项")


class FacebookSupportedQualitiesResponse(BaseModel):
    """Facebook支持的质量选项响应DTO"""
    qualities: List[str] = Field(..., description="支持的质量选项")
    default_quality: str = Field(..., description="默认质量")
    description: str = Field(..., description="说明")
    
    
class FacebookUrlTypesResponse(BaseModel):
    """Facebook支持的URL类型响应DTO"""
    url_types: List[Dict[str, str]] = Field(..., description="支持的URL类型")
    examples: Dict[str, str] = Field(..., description="URL示例")
    description: str = Field(..., description="说明") 